library(openxlsx)
library(lmerTest)

# Linear mixed model for figure 1A for new authors (red and orange lines)
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"Authors1LastFull~Year*JournalType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)

# Linear mixed model for figure 1A for intermediate authors (blue and light blue lines)
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"AuthorsIntermediateJournal~Year*JournalType+(1|Journal)" # Model
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)

# Linear mixed model for figure 1C (restricted access to data)
Matrice<-read.xlsx("FullPath\\AnalyseMixedModelJournalTime2Filtered1AllEditors2Full.xlsx",sheet=1,startRow=1,colNames=TRUE) # FullPath must be replaced by the full path to the directory where the file is saved
Model<-"Authors1LastFull~Year*NArticles+Year*ResearchExp+Year*EditorialExp+Year*JournalType+(1|Editor)" # Model for new authors
Model<-"AuthorsIntermediateJournal~Year*NArticles+Year*ResearchExp+Year*EditorialExp+Year*JournalType+(1|Editor)" # Model for known intermediate authors
Resultat<-lmer(Model,data=Matrice)
hist(resid(Resultat)) # Display residuals
summary(Resultat)








